using IQIGame.Onigao.Framework;

namespace IQIGame.Onigao.Logic
{
    /// <summary>
    /// 延迟执行的行为，关卡专用，不保存
    /// 主要针对需要延迟的实体行为
    /// 需要保存的延迟优先通过延迟服务实现
    /// 不保存的行为可能存在的问题可参考EntityOccupationStatus的相关注释
    /// </summary>
    public abstract class LgLevelDelayActionBase : IReusableClass
    {
        protected LevelPlayer player;
        protected int execFrame;

        public abstract uint MaxStore { get; }
        public LevelEntity entity { get; protected set; }
        public bool isExpired { get; private set; }
        public LevelRegion region => entity.region;

        protected void Init(LevelPlayer player, LevelEntity entity, int delayFrame)
        {
            this.player = player;
            this.entity = entity;
            this.execFrame = region.level.levelFrame + delayFrame;
        }

        public abstract void OnExecute();

        public void LogicOnUpdate()
        {
            if (isExpired)
                return;
            if (entity.region.level.levelFrame > execFrame)
            {
                OnExecute();
                isExpired = true;
            }
        }

        public virtual void OnReset()
        {
            player = null;
            entity = null;
            execFrame = 0;
            isExpired = false;
        }
    }
}
